package cn.sciento.oauth.security.sms.config;

import cn.sciento.oauth.domain.service.AuditLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.sciento.core.captcha.CaptchaMessageHelper;
import cn.sciento.oauth.security.config.SecurityProperties;
import cn.sciento.oauth.security.custom.CustomUserDetailsService;
import cn.sciento.oauth.security.service.LoginRecordService;
import cn.sciento.oauth.security.service.UserAccountService;
import cn.sciento.oauth.security.sms.SmsAuthenticationDetailsSource;
import cn.sciento.oauth.security.sms.SmsAuthenticationFailureHandler;
import cn.sciento.oauth.security.sms.SmsAuthenticationProvider;

/**
 * 短信登录配置
 *

 */
@Configuration
public class SmsLoginConfiguration {

    @Autowired
    private CustomUserDetailsService userDetailsService;
    @Autowired
    private CaptchaMessageHelper captchaMessageHelper;
    @Autowired
    private UserAccountService userAccountService;
    @Autowired
    private LoginRecordService loginRecordService;
    @Autowired
    private SecurityProperties securityProperties;
    @Autowired
    private AuditLoginService auditLoginService;

    @Bean
    public SmsAuthenticationFailureHandler smsAuthenticationFailureHandler() {
        return new SmsAuthenticationFailureHandler(loginRecordService, securityProperties, auditLoginService);
    }

    @Bean
    public SmsAuthenticationDetailsSource smsAuthenticationDetailsSource() {
        return new SmsAuthenticationDetailsSource();
    }

    @Bean
    public SmsAuthenticationProvider smsAuthenticationProvider() {
        return new SmsAuthenticationProvider(userDetailsService, captchaMessageHelper,
                userAccountService, loginRecordService);
    }

}
